package com.atguigu.crowd.mvc.handler;

import com.atguigu.crowd.constant.CrowdConstant;
import com.atguigu.crowd.entity.Admin;
import com.atguigu.crowd.entity.Member;
import com.atguigu.crowd.service.api.AuthMemberService;
import com.github.pagehelper.PageInfo;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

//审核页面
@Controller
public class AuthMemberHandler {


    @Autowired
    private AuthMemberService authMemberService;

    //身份认证审核页面 分页 关键词查询
    @RequestMapping("/auth/member/page.html")
    public String getAuthMemberInfo(
            //keyword有时有 有时无 设置默认为空字符串
            @RequestParam(value = "keyword",defaultValue = "") String keyword,
            //pageNum 默认值设为1
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            //pageSize 默认值设为5
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
            ModelMap modelMap
    ){
//        System.out.println("身份审核页面");
        PageInfo<Member> MemberPageInfo = authMemberService.getAuthMemberPageInfo(keyword, pageNum, pageSize);

        List<Member> list = MemberPageInfo.getList();

        System.out.println("pageInfo.list.size: "+list.size());
        System.out.println("pageInfo.list: "+list.get(0));

        modelMap.addAttribute("auth_member",MemberPageInfo);


        return  "auth-cert";

    }

    //审核通过/不通过删除
    @RequestMapping("/auth/member/change.html")
    public String changeMember(
            //keyword有时有 有时无 设置默认为空字符串
            @RequestParam(value = "keyword",defaultValue = "") String keyword,
            //pageNum 默认值设为1
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            //pageSize 默认值设为5
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
            ModelMap modelMap,
            @RequestParam(value = "change")Integer change,
            @RequestParam(value = "memberId")Integer memberId
            ){

//        System.out.println("change: "+change);
        if(change==1){
            //审核通过
            authMemberService.updateMemberAuthstatusPass(memberId);
        }else if (change==2){
            //审核不通过
            authMemberService.updateMemberAuthstatusNotPass(memberId);
        }

        return "redirect:/auth/member/page.html?pageNum="+pageNum+"&keyword="+keyword;
    }




    //审核不通过删除










}
